package com.mroapp.fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;

import com.mroapp.R;

/**
 * Created by apple on 16/7/13.
 */
public class ShoppingFragment extends Fragment{
    private TextView  title_name;
    private WebView business_webview;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_shop,container,false);
        title_name=(TextView)view.findViewById(R.id.title_name);
        title_name.setText("魔龙商城");
        initView(view);
        return view;
    }

    public void initView(View view){
        business_webview=(WebView)view.findViewById(R.id.shop_webview);
        business_webview.loadUrl("http://www.taobao.com");
        business_webview.setWebViewClient(new WebViewClient());
        WebSettings webSettings=business_webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        business_webview.addJavascriptInterface(new WebAppInterface(ShoppingFragment.this.getActivity()),"Android");
    }


    class WebAppInterface {
        Context mContext;

        /** Instantiate the interface and set the context */
        WebAppInterface(Context c) {
            mContext = c;
        }

        /** Show a toast from the web page */
        @JavascriptInterface
        public void showToast(String toast) {
            Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
        }
    }

}
